package com.woniu.customer.contorller;

import com.alibaba.fastjson.JSONObject;
import com.woniu.aop.OperationLogAnnotation;
import com.woniu.customer.entity.Customer;
import com.woniu.customer.entity.GoodOrder;
import com.woniu.customer.entity.vo.InvestmentVO;
import com.woniu.customer.service.CustomerService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.MinioUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/customer")
@Slf4j
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("login")
    public HttpResult<?> login(@RequestBody Customer customer) {
        return customerService.login(customer);
    }

    @PostMapping("register")
    public HttpResult<?> register(@RequestBody Customer customer) {
        return customerService.register(customer);
    }

    @GetMapping("find_by_phone")
    public HttpResult<?> findByPhone(String phone) {
        return customerService.findCustomerByPhone(phone);
    }

    @PostMapping("update_information")
    public HttpResult<?> updateCustomerinformation(@RequestBody Customer customer) {
        return customerService.updateCustomerinformation(customer);
    }

    @GetMapping("select_good_list")
    public HttpResult<?> selectGoodList(){
        return customerService.selectGoodList();
    }

    @GetMapping("cut_grade")
    public HttpResult<?> cutGoodGrade(String phone, Integer grade){
        return customerService.cutGoodGrade(phone, grade);
    }

    @PostMapping("add_good_order")
    public HttpResult<?> addGoodOrder(@RequestBody GoodOrder goodOrder){
        return customerService.addGoodOrder(goodOrder);
    }

    @GetMapping("select_good_order_list")
    public HttpResult<?> selectGoodOrderList(String phone){
        return customerService.selectGoodOrderList(phone);
    }


    @PostMapping("invest")
    @OperationLogAnnotation(operModul = "用户-投资", operType = "查询,新增,修改", operDesc = "用户进行投资操作")
    public HttpResult<?> CustomerInvest(InvestmentVO investment) {
        return customerService.CustomerInvest(investment);
    }

    @Autowired
    private MinioUtils minioUtils;

    @PostMapping("/uploadimg")
    public JSONObject uploadimg(MultipartFile file ) {
        JSONObject test = null;
        try {
            test = minioUtils.uploadFile(file, "test");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return test;
    }
}
